package cn.wzvtc.common.dto;

import lombok.Getter;
import lombok.Setter;

/**
 * @author Shiwei Xu
 * @date 2020/5/27
 */
@Getter
@Setter
public class Result<T> {

  private Integer code;

  private String msg;

  private T data;

  public Result(Integer code, String msg, T data) {
    this.code = code;
    this.msg = msg;
    this.data = data;
  }

  public static <E> Result ok(E data) {
    return new Result<>(0, "success", data);
  }

  public static Result<Void> ok() {
    return new Result<>(0, "success", null);
  }

  public static Result<Void> error() {
    return new Result<>(500, "error", null);
  }

  public static Result<Void> error(String msg) {
    return new Result<>(500, msg, null);
  }
}
